<?php require_once('../Connections/miportal.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "../private/login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../private/login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
  $MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php require_once('../Connections/miportal.php'); 
mysql_query("SET NAMES 'utf8'");?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$ies_rsPrimarias = "-1";
if (isset($_SESSION['MM_id_target'])) {
  $ies_rsPrimarias = $_SESSION['MM_id_target'];
}

mysql_select_db($database_miportal, $miportal);
$query_rsPrimarias = "SELECT * FROM `cor_ies_primaria` JOIN `cat_primaria` USING (`id_cat_primaria`) WHERE `id_cat_ies`=".$ies_rsPrimarias;
$rsPrimarias = mysql_query($query_rsPrimarias, $miportal) or die(mysql_error());
$row_rsPrimarias = mysql_fetch_assoc($rsPrimarias);
$totalRows_rsPrimarias = mysql_num_rows($rsPrimarias);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formRegPrimaria")) {
  $insertSQL = sprintf("INSERT INTO cat_primaria (nb_primaria, dt_direccion_completa, id_cve_sep, rep_titulo, rep_nom_responsable, rep_telefono, rep_extension, rep_correo, ties_titulo, ties_nombre_completo, ties_cargo, ties_grado, ties_relacion, ties_telefono, ties_extension, ties_correo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['insNombre'], "text"),
                       GetSQLValueString($_POST['insDireccion'], "text"),
                       GetSQLValueString($_POST['insCveSEP'], "text"),
                       GetSQLValueString($_POST['insTituloRes'], "text"),
                       GetSQLValueString($_POST['insRespPrimaria2'], "text"),
                       GetSQLValueString($_POST['insTelefono'], "text"),
                       GetSQLValueString($_POST['insExtensionRes'], "text"),
                       GetSQLValueString($_POST['insCorreoResp'], "text"),
                       GetSQLValueString($_POST['insTituloTut'], "text"),
                       GetSQLValueString($_POST['insNombreT'], "text"),
                       GetSQLValueString($_POST['insCargoT'], "text"),
                       GetSQLValueString($_POST['insGrado'], "text"),
                       GetSQLValueString($_POST['insRelacion'], "text"),
                       GetSQLValueString($_POST['insTelefonoT'], "text"),
                       GetSQLValueString($_POST['insExtension'], "text"),
                       GetSQLValueString($_POST['insCorreoT'], "text"));

  mysql_select_db($database_miportal, $miportal);
  $Result1 = mysql_query($insertSQL, $miportal) or die(mysql_error());
   //INICIO DEL SELECT PARA OBTENER DATOS DE REGISTRO

  $query_rs = sprintf("SELECT id_cat_primaria, id_cve_sep, nb_primaria FROM cat_primaria  WHERE id_cve_sep = %s", GetSQLValueString($_POST['insCveSEP'], "text"));
$rs = mysql_query($query_rs, $miportal) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
 //FIN DEL SELECT LO ENVIAMOS 
    //REALIZAMOS RELACIÓN IES PRIMARIA
  
    $insert_ies_empresa= sprintf("INSERT INTO cor_ies_primaria (id_cat_convocatoria, id_cat_programa, id_cat_ies, id_cat_primaria) 
	VALUES 	(%s, %s, %s, %s)",
                       GetSQLValueString(20, "int"),
					   GetSQLValueString($_SESSION['MM_tp_programa'], "text"),
					   GetSQLValueString($_SESSION['MM_id_target'], "text"),
					   GetSQLValueString($row_rs['id_cat_primaria'], "text"));
   mysql_select_db($database_miportal, $miportal);
  $Result1 = mysql_query($insert_ies_empresa, $miportal) or die(mysql_error());
//FIN INSERT  IES PRIMARIA
//EN HEAFES BY POST
  $insertGoTo = "form_confirm_asignacion.php?folio_primaria=".base64_encode($row_rs['id_cat_primaria'])."&nomPrimaria=".base64_encode($row_rs['nb_primaria']);
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


if ((isset($_POST["MM_empresa"])) &&($_POST["MM_empresa"] == "formEmpresa_pre")) {
	 //INICIO DEL SELECT PARA OBTENER DATOS DE REGISTRO

  $query_rs = sprintf("SELECT id_cat_primaria, id_cve_sep, nb_primaria FROM cat_primaria WHERE id_cve_sep =%s", 
	GetSQLValueString($_POST['slEmpresa'], "text"));
	$rs = mysql_query($query_rs, $miportal) or die(mysql_error());
	$row_rs = mysql_fetch_assoc($rs);
	$totalRows_rs = mysql_num_rows($rs);
 //FIN DEL SELECT LO ENVIAMOS

 //EN HEAFES BY POST
 
  $insertGoTo = "form_confirm_asignacion.php?folio_primaria=".base64_encode($row_rs['id_cat_primaria'])."&nomPrimaria=".base64_encode($row_rs['nb_primaria']);
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
 
  header(sprintf("Location: %s", $insertGoTo));
}

?>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximun-scale=1">
<title>FUNDACIÓN EDUCACIÓN SUPERIOR-EMPRESA</title>
<!--Hoja de estilo principal-->
<link href="../css/styletd2.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="shortcut icon" href="stylesheet/img/devil-icon.png"> 
<link rel="stylesheet" type="text/css" href="../css/mos-style.css">
<link rel="stylesheet" type="text/css" href="../css/menu.css"><!--Pemanggilan gambar favicon-->
 <!--pemanggilan file css-->
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css">
<script language=""="JavaScript">
	function conMayusculas(field) {
				field.value = field.value.toUpperCase()
		}
			function incubadora(val) {
				documen.write(val);
		}
	function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}

	function confirmar ( mensaje ) {
					return confirm( mensaje );
				}
        </script>
</head>
<body>

<header>
    <div id="background"></div>
  <div class="img_header_logo"></div>
    <span class="img_header_logo"><a href="http://fese.org.mx"><img src="../images/fese/FESE_home_logo.png"  height="90" alt="FESE" align="bottom" /></a></span>
    <div class="img_header_logo"></div>
    
  
<div id="nav">
<ul>
  <li class="nivel1"><a href="../private/rov.php" class="nivel1">Inicio</a></li>
  <li class="nivel1"><a href="../report/report_rov_candidatos.php" class="nivel1">Candidatos</a></li>
 
</ul>
</div><!--Menu NAV-->

</header>

<center>
<div id="boxcontainer">
<div id="container">
<div id="primarias"  style="visibility:visible" >
<hr>
<h2>PRIMARIAS  REGISTRADAS</h2>

<form name="empresas_pre" method="POST" action="">
  <p>
    <label>PRIMARIAS
      <select name="slEmpresa" id="slEmpresa">
	  <option selected="selected">Seleccione...</option>
        <?php
do {  
?>
        <option value="<?php echo $row_rsPrimarias['id_cve_sep']?>"><?php echo $row_rsPrimarias['nb_primaria']?></option>
        <?php
} while ($row_rsPrimarias = mysql_fetch_assoc($rsPrimarias));
  $rows = mysql_num_rows($rsPrimarias);
  if($rows > 0) {
      mysql_data_seek($rsPrimarias, 0);
	  $row_rsPrimarias = mysql_fetch_assoc($rsPrimarias);
  }
?>
      </select>
    </label>
  </p>
  <p>
  <input type="hidden" name="MM_empresa" value="formEmpresa_pre">
    <input type="submit" name="continuar" id="continuar" value="Continuar" <?php if($totalRows_rsPrimarias==0 ){echo "style=\"visibility:hidden\"";}?>>
  </p>
</form>
<p>&nbsp;</p>
<hr>
</div><!--PRIMARIAS-->
<div id="reg_primaria" <?php if($totalRows_rsPrimarias==2 ){echo "style=\"visibility:hidden\"";}?> >
<h2>REGISTRO DE PRIMARIA</h2>
<form action="<?php echo $editFormAction; ?>" method="POST" name="formRegPrimaria">
<table name="t_candidato" width="720px" border="1">
	
    <tr>
		<td colspan="2"><h3>DATOS DE LA ESCUELA PRIMARIA EN DONDE SE DESARROLLA EL PROGRAMA</h3></td>
		</tr>
    <tr>
		<td>Nombre de la escuela primaria</td>
		<td><span id="nombre">
		  <input type="text" name="insNombre" id="insNombre" onChange="conMayusculas(this)" style="width:280px">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
	  <td>Dirección completa (Calle y número)</td>
	  <td><span id="direccion">
	    <input type="text" name="insDireccion" id="insDireccion" onChange="conMayusculas(this)" style="width:280px">
	    <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	  </tr>
	
	<tr>
	  <td>Clave SEP</td>
	  <td><span id="clave_sep">
	    <input type="text" name="insCveSEP" id="insCveSEP" onChange="conMayusculas(this)" style="width:280px">
	    <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	  </tr>
	<tr>
	  <td colspan="2"><h3>Responsable de la escuela primaria<span id="cp2"><span class="textfieldRequiredMsg">Se necesita un valor.</span></span></h3></td>
	  </tr>
	<tr>
	  <td>Título</td>
	  <td><select name="insTituloRes" id="ins_titulo3">
	    <option value="C.">C.</option>
	    <option value="TSU.">TSU.</option>
	    <option value="LIC." selected>LIC.</option>
	    <option value="ING.">ING.</option>
	    <option value="MTRO.">MTRO.</option>
	    <option value="MTRA.">MTRA.</option>
	    <option value="DR.">DR.</option>
	    <option value="DRA.">DRA.</option>
	    </select></td>
	  </tr>
	<tr>
	  <td>Nombre Completo</td>
	  <td><input type="text" name="insRespPrimaria2" id="insRespPrimaria2" onChange="conMayusculas(this)" style="width:280px"></td>
	  </tr>
	<tr>
		<td>Teléfono</td>
		<td><span id="telefono">
        <input type="text" name="insTelefono" id="insTelefono" onChange="conMayusculas(this)" style="width:280px">
        <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldMinCharsMsg">No se cumple el mínimo de caracteres requerido.</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span><span class="textfieldInvalidFormatMsg">Formato no válido.</span></span></td>
	</tr>
	<tr>
	  <td>Extensión</td>
	  <td><input type="text" name="insExtensionRes" id="insExtensionRes" onChange="conMayusculas(this)" style="width:280px"></td>
	  </tr>
	<tr>
		<td>Correo electrónico</td>
		<td><span id="correo">
        <input type="text" name="insCorreoResp" id="insCorreoResp" onChange="conMayusculas(this)" style="width:280px">
        <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldInvalidFormatMsg">Formato no válido.</span></span></td>
	</tr>
	   
    <tr>
		<td colspan="2" ><h3>DATOS  DEL TUTOR ASIGNADO POR LA IES Y RESPONSABLE DEL PROGRAMA</h3></td>
		</tr>
	<tr>
	  <td>Título</td>
	  <td><select name="insTituloTut" id="insTituloTut">
				<option value="C.">C.</option>
			    <option value="TSU.">TSU.</option>
                <option value="LIC." selected>LIC.</option>
			    <option value="ING.">ING.</option>
			    <option value="MTRO.">MTRO.</option>
			    <option value="MTRA.">MTRA.</option>
			    <option value="DR.">DR.</option>
			    <option value="DRA.">DRA.</option>
		      </select></td>
	  </tr>
	<tr>
		<td>Nombre completo</td>
		<td><span id="nombretutor">
		  <input type="text" name="insNombreT" id="insNombreT" onChange="conMayusculas(this)" style="width:280px">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Cargo en la institución educativa</td>
		<td><span id="cargo">
		  <input type="text" name="insCargoT" id="insCargoT" onChange="conMayusculas(this)" style="width:280px">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Último grado de estudios</td>
		<td><span id="grado_estudios">
		  <input type="text" name="insGrado" id="insGrado" onChange="conMayusculas(this)" style="width:280px">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
		<td>Relación de la formación profesional con los alumnos asignados*</td>
		<td><span id="relacion">
		  <input type="text" name="insRelacion" id="insRelacion" onChange="conMayusculas(this)" style="width:280px">
		  <span class="textfieldRequiredMsg">Se necesita un valor.</span></span></td>
	</tr>
	<tr>
	  <td>Teléfono</td>
	  <td><span id="telefono_tutor">
	    <input type="text" name="insTelefonoT" id="insTelefonoT" onChange="conMayusculas(this)" style="width:280px">
	    <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldInvalidFormatMsg">Formato no válido.</span><span class="textfieldMinCharsMsg">No se cumple el mínimo de caracteres requerido.</span><span class="textfieldMaxCharsMsg">Se ha superado el número máximo de caracteres.</span></span></td>
	  </tr>
	<tr>
	  <td>Extensión</td>
	  <td><span id="telefono_tutor2">
	    <input type="text" name="insExtension" id="insExtension" onChange="conMayusculas(this)" style="width:280px">
<span class="textfieldMaxCharsMsg"><br>
Se ha superado el número máximo de caracteres.</span></span></td>
	  </tr>
	<tr>
	  <td>Correo electrónico</td>
	  <td><span id="correo_tutor">
	    <input type="text" name="insCorreoT" id="insCorreoT" onChange="conMayusculas(this)" style="width:280px">
	    <span class="textfieldRequiredMsg">Se necesita un valor.</span><span class="textfieldInvalidFormatMsg">Formato no válido.</span></span></td>
	  </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
		<td colspan="2" style="text-align:right;"><input type="submit" class="button" value="Guardar y continuar" onClick="return confirmar('¿Esta seguro que desea registrar los datos ingresados?')"></td>
		</tr>
    
</table>
<input type="hidden" name="MM_insert" value="formRegPrimaria">
</form>
</div><!--Registro primaria-->
</div><!--Container-->
<div id="rightContainer">
    <div id="Bienvenida">
    <div id="cuadro">
    <h1>Bienvenido</h1>
    </div>
    
    <div >
    <br>
            <?php echo $_SESSION['MM_UsName'] ?><br><br>
            <?php echo $_SESSION['MM_nmb_target'] ?><br>
            <a href="<?php echo $logoutAction ?>">Salir</a>
        </div>
    </div>
    <br style="clear:both"/>
    <div id="convocatoria">
    <div id="cuadro">
    <h1>Convocatoria</h1>
    </div>
    <br>
    <?php 
    if(isset($_SESSION['MM_tp_programa'])&$_SESSION['MM_tp_programa']=="Vigentes"){
        echo "<select name=\"slConvocatoria\">
        <option selected=\"selected\">Seleccione</option>
        <option value=\"empleate\">Empleate</option>
        <option value=\"experimenta\">Experimenta</option>
        <option value=\"mpe\">Mi Primera Empresa</option>
        <option value=\"vecas_vinculacion\">Vecas Vinculación</option>
        </select>
        "	;
    }else{
    echo $_SESSION['MM_tp_programa'];}
    ?>
    
    </div>
</div><!--contenedor derecho-->


</div><!--Boxcontainer-->
  
   
</center>
<script type="text/javascript">
var sprytextfield1 = new Spry.Widget.ValidationTextField("nombre", "none", {validateOn:["blur", "change"]});
var sprytextfield3 = new Spry.Widget.ValidationTextField("direccion", "none", {validateOn:["blur", "change"]});
var sprytextfield5 = new Spry.Widget.ValidationTextField("clave_sep", "none", {validateOn:["blur", "change"]});
var sprytextfield6 = new Spry.Widget.ValidationTextField("telefono", "integer", {validateOn:["blur", "change"], hint:"S\xF3lo 10 digitos", minChars:10, maxChars:10});
var sprytextfield7 = new Spry.Widget.ValidationTextField("correo", "email", {validateOn:["blur", "change"]});
var sprytextfield8 = new Spry.Widget.ValidationTextField("nombretutor", "none", {validateOn:["blur", "change"]});
var sprytextfield9 = new Spry.Widget.ValidationTextField("cargo", "none", {validateOn:["blur", "change"]});
var sprytextfield10 = new Spry.Widget.ValidationTextField("grado_estudios", "none", {validateOn:["blur", "change"]});
var sprytextfield11 = new Spry.Widget.ValidationTextField("relacion", "none", {validateOn:["blur", "change"]});
var sprytextfield12 = new Spry.Widget.ValidationTextField("telefono_tutor", "integer", {validateOn:["blur", "change"], minChars:10, maxChars:10, hint:"S\xF3lo 10 digitos"});
var sprytextfield13 = new Spry.Widget.ValidationTextField("correo_tutor", "email", {validateOn:["blur", "change"]});
var sprytextfield12 = new Spry.Widget.ValidationTextField("telefono_tutor2", "none", {validateOn:["blur", "change"], maxChars:6, hint:"m\xE1ximo 6 digitos", isRequired:false});
</script>
</body>
</html>
<?php
mysql_free_result($rsPrimarias);
?>
